# -*- coding: utf-8 -*-
# @Date：2025/5/26 14:24:14
# @Author：CJiaの用心
# @FileName：03-列表元素的删除.py
# @Editor：PyCharm2024
# @Remark：
# 1. del 删除指定位置的元素
a = [1, 2, 3, 4, 5, 6, 7, 8, 9]
del a[0]  # 1 -> [2, 3, 4, 5, 6, 7, 8, 9]
del a[5]  # 7 -> [2, 3, 4, 5, 6, 8, 9]
print(a)  # [2, 3, 4, 5, 6, 8, 9]

# 2. pop(索引) -> 默认删除列表最后一个元素, 返回删除的元素
b = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
b1 = b.pop()  # j
print("删除的元素：", b1, b)  # ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i']
b2 = b.pop(5)  # f
print("删除的元素：", b2, b)  # ['a', 'b', 'c', 'd', 'e', 'g', 'h', 'i']

# 3. remove() 删除首次(第一次)出现的元素, 不存在报错
c = [1, 2, 3, 1, 2, 4, 5, ]
c.remove(2)
print(c)  # [2, 3, 1, 4, 5]
